package com.community.system.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.community.common.annotation.Log;
import com.community.common.core.controller.BaseController;
import com.community.common.core.domain.AjaxResult;
import com.community.common.enums.BusinessType;
import com.community.system.domain.VehicleRecord;
import com.community.system.service.IVehicleRecordService;
import com.community.common.utils.poi.ExcelUtil;
import com.community.common.core.page.TableDataInfo;

/**
 * recordController
 * 
 * @author ruoyi
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/system/record")
public class VehicleRecordController extends BaseController
{
    @Autowired
    private IVehicleRecordService vehicleRecordService;



    /**
     * 查询record列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(VehicleRecord vehicleRecord)
    {
        startPage();
        List<VehicleRecord> list = vehicleRecordService.selectVehicleRecordList(vehicleRecord);
        return getDataTable(list);
    }

    /**
     * 导出record列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "record", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VehicleRecord vehicleRecord)
    {
        List<VehicleRecord> list = vehicleRecordService.selectVehicleRecordList(vehicleRecord);
        ExcelUtil<VehicleRecord> util = new ExcelUtil<VehicleRecord>(VehicleRecord.class);
        util.exportExcel(response, list, "record数据");
    }

    /**
     * 获取record详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(vehicleRecordService.selectVehicleRecordByRecordId(recordId));
    }

    /**
     * 新增record
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "record", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VehicleRecord vehicleRecord)
    {
        return toAjax(vehicleRecordService.insertVehicleRecord(vehicleRecord));
    }

    /**
     * 修改record
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "record", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VehicleRecord vehicleRecord)
    {
        return toAjax(vehicleRecordService.updateVehicleRecord(vehicleRecord));
    }

    /**
     * 删除record
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "record", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(vehicleRecordService.deleteVehicleRecordByRecordIds(recordIds));
    }

    /**
     * 车辆入场
     */
    @PreAuthorize("@ss.hasPermi('system:record:operate')")
    @Log(title = "record", businessType = BusinessType.UPDATE)
    @PostMapping("/in")
    public AjaxResult in(@RequestBody VehicleRecord vehicleRecord) {
        int rows = vehicleRecordService.insertVehicleRecordIn(vehicleRecord);
        System.out.println("车辆入场");
        return toAjax(rows);
    }

    /**
     * 车辆离场
     */
    @PreAuthorize("@ss.hasPermi('system:record:operate')")
    @Log(title = "record", businessType = BusinessType.UPDATE)
    @PostMapping("/out")
    public AjaxResult out(@RequestBody VehicleRecord vehicleRecord) {
        int i = vehicleRecordService.insertVehicleRecordOut(vehicleRecord);
        System.out.println("车辆离场");
        return toAjax(i);
    }
}
